[문자열 계산기] 이금주 미션 제출합니다.#3
Conversation
|
고생하셨습니다 |
yuninam2128
left a comment
There was a problem hiding this comment.
수고하셨습니다! 제가 완전 초보라서 질문만 적어두고 가네요..
| delimiter = new RergExp(customDelimeterMatch[1]); | ||
| input = customDelimeterMatch[2]; | ||
| } | ||
|
|
There was a problem hiding this comment.
match()는 자바스크립트에서 문자열(String) 객체에 내장된 메서드로 문자열 안에서 찾고자 하는 패턴을 정규 표현식을 이용해 검색하는 함수입니다. /^//(.)\n(.*)/ 의 정규 표현식에 매칭되도록 배열을 반환합니다. 위 코드에서 customDelimeterMatch[1] 은 Delimeter(예를 들면 ;)이 대입이 되어 있고 customDelimeterMatch[2]에는 사용자가 입력한 덧셈 식이 대입되어 있습니다.(예를 들면 1;2;3) match함수에 대해서는 스터디 정리글에서 자세히 다뤄보도록 하겠습니다!
There was a problem hiding this comment.
아앗 그리고 저 부분 오타입니닷,,,,RergExp가 아니라 RegExp에요 급해서 디버깅 안하고 내버려서^.^;;;; 사실 틀린 코드여서 안돌아갑니닷....
저도 완전 초보2입니닷,,,, |
| const customDelimeterMatch = input.match(/^\/\/(.)\n(.*)/); | ||
|
|
||
| if (customDelimeterMatch) { | ||
| delimiter = new RergExp(customDelimeterMatch[1]); |
There was a problem hiding this comment.
커스텀 구분자가 있으면 기본 구분자는 작동하지 않는 방식인 거 같네요
만약 둘 다 사용하고 싶으면 delimiter의 []안에 customDelimeterMatch를 넣으면 될 것 같네요!
| }); | ||
|
|
||
| return numbers.reduce((sum, num) => sum + num, 0); | ||
| } |
There was a problem hiding this comment.
map을 사용해서 배열을 순회하여 Number를 적용하셨네요
저는 reduce과정에서 Number를 적용하여 배열 순회를 덜하도록 코드를 작성했어요
const sum = inputArr.reduce((acc, cur) => {
const num = Number(cur);
(...)
}, 0);
이렇게 하면 시간복잡도 측면에서 조금 더 효율적이라고 하더라구요
근데 물론 큰 차이는 없는거 같긴 해요..ㅎㅎ
| if (!input) return 0; | ||
|
|
||
| let delimiter = /[,:]/; | ||
| const customDelimeterMatch = input.match(/^\/\/(.)\n(.*)/); |
There was a problem hiding this comment.
26행에서 (/^//(.)\n(.*)/)이 무슨 뜻인지 알 수 있을까요?
코드를 직접 돌려봤는데 실행이 잘 안 되는 거 같아서
이 부분이 무슨 뜻인지 알고 싶네요!
| const app = new App(); | ||
| app.play(); | ||
|
|
||
| export default App; |
There was a problem hiding this comment.
index없이 하나의 파일로 합치셨네요!
코드길이가 길지 않아서 이런 구조도 괜찮은 거 같습니다
1주차 미션 업로드